package com.xzx.spark.tuning.join

import com.xzx.spark.tuning.utils.InitUtil
import org.apache.spark.SparkConf
import org.apache.spark.sql.SparkSession

/**
 *
 * ${DESCRIPTION}
 *
 * @author xinzhixuan
 * @version 1.0
 * @date 2022-03-20 1:29 PM
 */
object AutoBroadcastJoinTuning {

  def main(args: Array[String]): Unit = {
    val sparkConf = new SparkConf().setAppName("BroadcastJoinTuning")
      .set("spark.sql.autoBroadcastJoinThreshold","-1") // 关闭自动广播
      .set("spark.sql.autoBroadcastJoinThreshold","1024")
      .setMaster("local[*]") //TODO 要打包提交集群执行，注释掉
    val sparkSession: SparkSession = InitUtil.initSparkSession(sparkConf)


    val sqlstr =
      """
        |select
        |  sc.courseid,
        |  csc.courseid
        |from sale_course sc join course_shopping_cart csc
        |on sc.courseid=csc.courseid
      """.stripMargin

    sparkSession.sql("use sparktuning;")
    // sparkSession.sql(sqlstr).show()
    sparkSession.sql(sqlstr).explain()

    InitUtil.hangOn()

  }
}
